<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>desktop</title>
		<style type="text/css">
               body{
                    background:#ffffdd;
               }
               div{
                    background:#bbffff;
                    margin:10px;
                    width:100px;
                    height:50px;
                    position:absolute;
               }
               #a{
                    width:80%;
                    height:80%;
                    background:#bbbbbb;
                    position:absolute;
               }
          </style>
          <script>
               window.onresize = x;
               window.onload = x;
               function x(){
                    var n = parseInt(document.getElementById("a").offsetHeight/70);
                    var m = parseInt(document.getElementById("a").offsetWidth/120);
                    var e = document.getElementsByTagName("div");
                    for(var i=1; i<e.length; i++){
                         if(i<=n*m){
                              e[i].style.left=0+parseInt((i-1)/n)*120;
                              e[i].style.top=0+((i-1)%n)*70;//使用doctype这里就无效，奇怪。
                              e[i].style.display="block";
                         }else{
                              e[i].style.display="none";
                         }
                    }
               }
               function add(){
                    document.getElementById("a").innerHTML+="<div>xxx</div>";
                    x();
               }
          </script>
</head>
<body>
	<input type="button" value="click" onclick="add();" />
	<div id="a">
		<div id="a1">
		     a1
		</div>
		<div id="a2">
		     a2
		</div>
		<div id="a3">
		     a3
		</div>
		<div id="a4">
		     a4
		</div>
		<div id="a5">
		     a5
		</div>
		<div id="a6">
		     a6
		</div>
		<div id="a7">
		     a7
		</div>
		<div id="a8">
		     a8
		</div>
		<div id="a9">
		     a9
		</div>
		<div id="a10">
		     a10
		</div>
	</div>
</body>
</html>